#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
use JSON;
use Sys::Hostname qw(hostname);
use Sys::Syslog;
use POSIX;

my $host = hostname;

my $date= strftime('%s', localtime);

my $HOSTNAME_CACTI="$host";

my $LOG_NAME = "logger";
my $SYSLOG_FACILITY= "local5.info";

my $url = "http://loghost:8080/server-statistics/json";
my $flair = get ($url);
my $parsed = from_json ($flair);
#print "$parsed->{cacheHitRate5min}\n";

#print("UOLGRAPH lighttpd_video_statistics 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " cacheHitRate5min " .$parsed->{"cacheHitRate5min"});

# Graficos de Connections
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_conn 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_client_conn " .$parsed->{clientConnections});
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_conn 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_be_conn " .$parsed->{backendConnections});

# Graficos de estatisticas de cache
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_rate 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_hit_perc " .$parsed->{cacheHitRate5min});
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_mem 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_hit_young " .$parsed->{youngHitRate5min});
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_mem 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_hit_mux " .$parsed->{muxHitRate5min}); 
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_mem 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_hit_old " .$parsed->{oldHitRate5min});
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_mem 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_hit_pop " .$parsed->{popHitRate5min});
syslog ($SYSLOG_FACILITY, "UOLGRAPH check_hit_mem 10 " .$HOSTNAME_CACTI. " AGENTE_LASTRUN " .$date. " uolmais_miss " .$parsed->{missHitRate5min});
